<?php
session_start();
/*
if (empty($_SESSION['username']) AND empty($_SESSION['passuser'])){
  echo "<link href='style.css' rel='stylesheet' type='text/css'>
 <center>Untuk mengakses modul, Anda harus login <br>";
  echo "<a href=../../index.php><b>LOGIN</b></a></center>";
}
else{
*/
include "../../../config/koneksi.php";
include "../../../config/library.php";
include "../../../config/fungsi_thumb.php";

$module=$_GET['mod'];
$act=$_GET['act'];

// Hapus slide
if ($module=='slide' AND $act=='hapus'){
  $data=mysql_fetch_array(mysql_query("SELECT * FROM slide WHERE id_gambar='$_GET[id]'"));
  if ($data['nama_gambar']!=''){
     mysql_query("DELETE FROM slide WHERE id_gambar='$_GET[id]'");
     unlink("../../../image/$_GET[namafile]");   
  }
  else{
    mysql_query("DELETE FROM slide WHERE id_gambar='$_GET[id]'");
  }
  header('location:../../dasbord.php?mod='.$module);
}

// Input slide
elseif ($module=='slide' AND $act=='input'){
  $lokasi_file = $_FILES['fupload']['tmp_name'];
  $tipe_file      = $_FILES['fupload']['type'];
  $nama_file   = $_FILES['fupload']['name'];

  // Apabila ada gambar yang diupload
  	UploadBanner($nama_file);
    mysql_query("INSERT INTO slide (date, nama_gambar)
                            VALUES ('$tgl_sekarang','$nama_file')");
							
   header('location:../../dasbord.php?mod='.$module);
  
}

// Update slide
elseif ($module=='slide' AND $act=='update'){
  $lokasi_file = $_FILES['fupload']['tmp_name'];
  $tipe_file      = $_FILES['fupload']['type'];
  $nama_file   = $_FILES['fupload']['name'];

$sql="select * from slide where id_gambar=$_POST[id]";
$query=@mysql_query($sql);
$r=@mysql_fetch_array($query);
 unlink("../../../image/$r[nama_gambar]");  

  // Apabila gambar tidak diganti
  UploadBanner($nama_file);
    mysql_query("UPDATE slide SET nama_gambar    = '$nama_file'   
                             WHERE id_gambar = '$_POST[id]'");

  header('location:../../dasbord.php?mod='.$module);
   
}
//}
?>
